package com.googlecode.ws.tester.xor.wsdl;

import org.xml.sax.SAXException;
import org.w3c.dom.Document;
import org.w3c.dom.NodeList;
import org.w3c.dom.Node;
import org.w3c.dom.NamedNodeMap;

import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import java.io.IOException;

import com.googlecode.ws.tester.xor.engine.Config;
import com.googlecode.ws.tester.xor.engine.Element;
import com.googlecode.ws.tester.xor.engine.Parser;

/**
 * Created by IntelliJ IDEA.
 * User: pablo
 * Date: 2009-06-09
 * Time: 18:41:44
 */
public class Test {
    public static void main(String[] args) throws ParserConfigurationException, IOException, SAXException {
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        Config config = new Config();
        factory.setValidating(false);
        Document document = factory.newDocumentBuilder().parse(Test.class.getClassLoader().getResourceAsStream("com/googlecode/ws/tester/xor/wsdl/config/parser-conf.xml"));
        NodeList list = document.getElementsByTagName("element");
        int i = list.getLength();
        for(int j = 0;j<i;j++ ) {
            Node node = list.item(j);
            NamedNodeMap attributes = node.getAttributes();
            Element element = new Element();
            element.setClassName(attributes.getNamedItem("class").getNodeValue());
            element.setNamespaces(attributes.getNamedItem("namespaces").getNodeValue());
            element.setRoot(attributes.getNamedItem("root").getNodeValue());
            element.setCollection(attributes.getNamedItem("collection").getNodeValue());
            System.out.println(element);
            config.getElements().put(attributes.getNamedItem("name").getNodeValue(), element);
        }
        Parser p = new Parser(config);
        System.out.println(p.getResult());
    }
}
